#pragma once
#include<vector>

#include<functional>
namespace bit

{
    template <class T, class Container = vector<T>, class Compare = less<T> >
    class priority_queue
    {
    public:

        bool empty() const
        {
            return c.empty();
        }
        void adjustup(int child)
        {
            int partent = (child - 1) / 2;
            while (child != 0&& comp(c[partent], c[child]))
            {
                swap(c[child], c[partent]);
                child = partent;
                partent = (child - 1) / 2;
            }
        }
        size_t size() const
        {
            return c.size();
        }


        const T& top()
        {
            return c[0];
        }

        void push(const T& x)
        {
            c.push_back(x);
            adjustup(c.size() - 1);
        }
        void adjustdown(int partent)
        {
            int child = partent * 2 + 1;
            if (child + 1 < c.size() && comp(c[partent], c[child]))
            {
                child = child + 1;
            }
            while (child < c.size() && comp(c[partent], c[child]))
            {
                swap(c[child], c[partent]);
                partent = child;
                child = partent * 2 + 1;
                if (child + 1 < c.size() && comp(c[partent], c[child]))
                {
                    child = child + 1; 
                }

            }
        }
        void pop()
        {
           // swap(c.fornt(), c.back());
            swap(c[0], c[c.size() - 1]);
            c.pop_back();
            adjustdown(0);
        }
    private:

        Container c;
        Compare comp;
    };
 
};
